import * as React from 'react'
import { Toast } from 'antd-mobile'
import { NavBar, PayInput } from 'components'
import './index.less'
import { post } from '../../../utils'

export default class Authentication extends React.Component<any, any> {
    public render(): JSX.Element {
        return (
            <div className="authentication">
                <NavBar title="身份验证" />
                <div className="authentication_label">请输入原支付密码</div>
                <div style={{ padding: '0 0.85rem', marginTop: '1.65rem' }}>
                    <PayInput autoFoucs={true} onComplete={this.handleVerifyPsw} />
                </div>
            </div>
        )
    }
    private handleVerifyPsw = (val: string) => {
        const { userInfo } = this.props
        Toast.info('验证中...', 0)
        post('usersapi/userPayPwdGet', {
            userId: userInfo.id,
            paypwd: val
        }).then((data: any) => {
            if (data.code === 0) {
                Toast.info('密码错误', 2)
            }
            if (data.code === 2) {
                Toast.info('验证通过', 2, () => {this.props.history.push('/My/authenticationNewPass/0')})
            }
        }).catch(() => {
            Toast.hide()
        })
    }
}